package com.agua.enturno.vista.modelos;

import org.apache.wicket.model.IModel;
import org.joda.time.Duration;


public class HoursInNumberModel implements IModel<Integer> {
	
	private static final long serialVersionUID = 1L;
	
	private IModel<Duration> hoursInDurationModel;
	
	public HoursInNumberModel(IModel<Duration> hoursInDurationModel) {
		this.hoursInDurationModel = hoursInDurationModel;
	}

	@Override
	public void detach() {
		hoursInDurationModel.detach();
	}

	@Override
	public Integer getObject() {
		return hoursInDurationModel.getObject().toPeriod().getHours();
	}

	@Override
	public void setObject(Integer object) {
		this.hoursInDurationModel.setObject(this.hoursInDurationModel.getObject().toPeriod().withHours(object).toStandardDuration());
	}
	
}
